﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Sita.Entities;
using Sita.Data.Repositories;

namespace Sita.MainModule.Services
{
    public class PermissionService
    {
        PermissionRepository PermissionRepository;

        public PermissionService()
        {
            PermissionRepository = new PermissionRepository();
        }


        //public int AddPermission(Permission permission)
        //{

        //    PermissionRepository.Add(permission);
        //    PermissionRepository.StoreContext.Commit();

        //    return permission.PermissionID;
        //}

        //public bool ModifyPermission(Permission permission)
        //{
        //    PermissionRepository.Modify(permission);

        //    PermissionRepository.StoreContext.Commit();

        //    return true;
        //}

        //public IList<Permission> GetPermissions()
        //{
        //    return PermissionRepository.GetAll().ToList();
        //}

        //public IList<Permission> GetPaginatedPermissions(int pageIndex, int pageSize, string sortColumn, bool ascending, int moduleID, out int totalRows)
        //{
        //    if (moduleID == -1)
        //    {
        //        return PermissionRepository.GetAllPaginatedWithInclude(pageIndex, pageSize, sortColumn, 
        //            ascending, "Module", out totalRows).ToList();
        //    }
        //    else
        //    {
        //        return PermissionRepository.GetAllPaginatedWithInclude(pageIndex, pageSize,
        //            new DirectSpecification<Permission>(m => m.ModuleID == moduleID),
        //                sortColumn, ascending, "Module", out totalRows).ToList();
        //    }
        //}

        public IList<Permission> GetPermissionsByUserID(int userID)
        {
            return PermissionRepository.GetByUserID(userID);
        }

        //public Permission GetPermissionByID(int permissionID)
        //{
        //    return PermissionRepository.GetByID(permissionID);
        //}

        //public Permission GetPermissionByCode(string code)
        //{
        //    return PermissionRepository.GetFiltered(p => p.Code == code).SingleOrDefault();
        //}

        //public bool DeletePermission(Permission permission)
        //{
        //    PermissionRepository.Delete(permission);
        //    PermissionRepository.StoreContext.Commit();

        //    return true;
        //}
    }
}
